package buber.genetic;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import buber.genetic.interfaces.Chromosome;
import buber.genetic.interfaces.Member;

public class SimpleMember implements Member {
	private List<Chromosome> chromosomes;
	private int chromosomeSize=20;
	private int chromosomeCount=1;
	public SimpleMember(){
		chromosomes=new ArrayList<Chromosome>();
	}
	public List<Chromosome> getChromosomes() {
		return chromosomes;
	}

	public void setChromosomes(List<Chromosome> chromosomes) {
		this.chromosomes = chromosomes;
	}
	public String asString(){
		StringBuffer sb = new StringBuffer();
		for(Iterator<Chromosome> mit = chromosomes.iterator();mit.hasNext();){
			sb.append(mit.next().asString());
		}
		return sb.toString();
	}
	public void init(){
			for(int i=0;i<chromosomeCount;i++){
				Chromosome ch = new ChromosomeArray(chromosomeSize);
				ch.init();
				chromosomes.add(ch);
			}
	}
	public Member getClone() {
		Member m = new SimpleMember();
		List<Chromosome> chl = new ArrayList<Chromosome>();
		for(Iterator<Chromosome> it = chromosomes.iterator();it.hasNext();){
			chl.add(it.next().getCopy());
		}
		m.setChromosomes(chl);
		return m; 
	}
	public int chSize(){
		return chromosomes.get(0).getSize();
	}
	public String geneString() {
		StringBuffer sb = new StringBuffer();
		for(Iterator<Chromosome> mit = chromosomes.iterator();mit.hasNext();){
			sb.append(mit.next().geneString());
		}
		return sb.toString();
	}
	public int getChromosomeSize() {
		return chromosomeSize;
	}
	public void setChromosomeSize(int chromosomeSize) {
		this.chromosomeSize = chromosomeSize;
	}
	public int getChromosomeCount() {
		return chromosomeCount;
	}
	public void setChromosomeCount(int chromosomeCount) {
		this.chromosomeCount = chromosomeCount;
	}

}
